Unrecognized attribute “targetFramework” when deploying asp.net 4.0

Ok you start developement with .net framework 4.0 and possibly try to deploy your site to iis first time and getting this error :Unrecognized attribute “targetFramework” when deploying asp.net 4.0 Because you did not configure your iis run with .net framework 4.0.

For do it you have to change your path to

C:\Windows\Microsoft.NET\Framework64\v4.0.30319

that execute command of

aspnet_regiis.exe -iru

if you already do this and getting this error you should better to check your site application pool for correct .NET framework version chosen.

Application Pools->Select yours -> Basic Settings -> And change .NET framework version

Thats it folks.

 

Advertisement

Redirect your site with http 301 permenantly to new domain

Redirect your site with http 301 permenantly to new domain

You want to move your site to new domain and dont want to lose your page rank in google search engine.This post has contains some instructions that how to use redirect your site with http 301 permenantly moved status code.

301 means the requested resource has been assigned to a new permanent Uniform Resource Identifier (URI), and any future references to this resource should be done using one of the returned URIs. 

Here is the road map

1)    use  301 Redirect (see httpmodule code in below). and make page to page basis redirection.

2)      Find external links by googling “link:www.yoursite.com”. If some of them has static links to “yoursite”, we must inform the webmasters to change the link.

3)      Track broken links with Xenu (this is an automated tool, that checks all links in a web site and prepare a report about broken links etc.)

4)      Domain www.yoursite.nl should be active for some time (min  180 days) after redirecting is activated.

5)      Add your new site’s url to Google Web Administration Tools.

6)      Prepare a new site map and add this to Google Web Administration Tools.

7)      Check SiteMap details page from time to time, to see how many URL’s google indexed from the new domain.

An example httpModule for redirect request with 301 permenant moved

using System;
using System.Web;
using System.Configuration;
using System.Web.Caching;
using System.Collections.Generic;
 
namespace YourSite
{
    /*
 * This HTTPModule Intercepts the Application Cycle, and performs a 301 Redirect to the domain 
 * parameter given in the web.config file - "newURL"
 */
 
    public class RedirectorModule : IHttpModule
    {
        /// <summary>
        /// You will need to configure this module in the web.config file of your
        /// web and register it with IIS before being able to use it. For more information
        /// see the following link: http://go.microsoft.com/?linkid=8101007
        /// </summary>
        #region IHttpModule Members
 
        // The Dictionary that will hold the URLMapping rules
        Dictionary<string, string> URLMapping = new Dictionary<string, string>();
 
        public void Dispose()
        {
            //clean-up code here.
        }
 
        public void Init(HttpApplication context)
        {
            // Below is an example of how you can handle LogRequest event and provide 
            // custom logging implementation for it
            //context.LogRequest += new EventHandler(OnLogRequest);
 
            // INTERCEPT PostResolveRequestCache PHASE
            context.PostResolveRequestCache += new EventHandler(context_PostResolveRequestCache);
        }
 
        void context_PostResolveRequestCache(object sender, EventArgs e)
        {
            // GET APPLICATION AND REQUEST
            HttpApplication app = (HttpApplication)sender;
            HttpRequest request = app.Context.Request;
 
            // TAKE FILE NAME FROM WEB.CONFIG
            string fileName = ConfigurationManager.AppSettings["URLMappingFilePath"];
            string filePath = app.Context.Server.MapPath(fileName);
 
            // CHECK IF URLMAPPING DICTIONARY IS IN CACHE
            if (app.Context.Cache["URLMapping"] == null)
            {
                //
                CacheDependency dependency = new CacheDependency(filePath);
                app.Context.Cache.Insert("URLMapping", URLMapper.DeserializeObject(filePath), dependency);
                URLMapping.Clear();
            }
 
            URLMapping = (System.Collections.Generic.Dictionary<string, string>)app.Context.Cache["URLMapping"];
 
            string lRequestedPath = request.Url.ToString();
            string requestedURL = request.RawUrl.ToString();
 
            if (!CheckFileExtension(requestedURL)) return;
 
            //REMOVE QUESTION MARK AT THE END
            if (requestedURL.Substring(requestedURL.Length - 1).Equals("?"))
                requestedURL = requestedURL.Substring(0, requestedURL.Length - 1);
 
 
            // WHEN USING IN LOCAL WE SHOULD REMOVE APPLICATION NAME FROM URL, 
            // BEFORE WE LOOK TO THE URL MAPPING
            string localAppName = ConfigurationManager.AppSettings["localAppName"];
            if (requestedURL.ToLower().Contains(localAppName.ToLower()))
            {
                requestedURL = requestedURL.Replace(localAppName, "");
            }
 
            if (URLMapping.ContainsKey(requestedURL))
            {
                requestedURL = URLMapping[requestedURL];
            }
 
            string newURL = ConfigurationManager.AppSettings["newURL"];
            string urlToGo = newURL + requestedURL;
 
            app.Response.StatusCode = System.Net.HttpStatusCode.MovedPermanently; // 301
            app.Response.AddHeader("Location", urlToGo);
            app.Response.End();
        }
 
        private bool CheckFileExtension(string requestedURL)
        {
            if (requestedURL.Contains("favicon.ico"))
            {
                return false;
            }
            return true;
        }
 
        #endregion
 
        public void OnLogRequest(Object source, EventArgs e)
        {
            //custom logging logic can go here
        }
    }
}
 
see all Http Status Codes
http://msdn.microsoft.com/en-us/library/aa383887(VS.85).aspx
check your site's page rank
http://www.googlepagerankchecker.com/
For broken links
http://home.snafu.de/tilman/xenulink.html

 

more to see for 301 redirection

http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=93633

 

 
 
 

IIS 7.0 Application Life Cycle

 

The following tasks are performed by the HttpApplication class while the request is being processed. The events are useful for page developers who want to run code when key request pipeline events are raised. They are also useful if you are developing a custom module and you want the module to be invoked for all requests to the pipeline. Custom modules implement the IHttpModule interface. In Integrated mode in IIS 7.0, you must register event handlers in a module’s Init method.

  1. Validate the request, which examines the information sent by the browser and determines whether it contains potentially malicious markup. For more information, see ValidateRequest and Script Exploits Overview.
  2. Perform URL mapping, if any URLs have been configured in the UrlMappingsSection section of the Web.config file.
  3. Raise the BeginRequest event.
  4. Raise the AuthenticateRequest event.
  5. Raise the PostAuthenticateRequest event.
  6. Raise the AuthorizeRequest event.
  7. Raise the PostAuthorizeRequest event.
  8. Raise the ResolveRequestCache event.
  9. Raise the PostResolveRequestCache event.
  10. Raise the MapRequestHandler event. An appropriate handler is selected based on the file-name extension of the requested resource. The handler can be a native-code module such as the IIS 7.0 StaticFileModule or a managed-code module such as the PageHandlerFactory class (which handles .aspx files). 
  11. Raise the PostMapRequestHandler event.
  12. Raise the AcquireRequestState event.
  13. Raise the PostAcquireRequestState event.
  14. Raise the PreRequestHandlerExecute event.
  15. Call the ProcessRequest method (or the asynchronous version IHttpAsyncHandler.BeginProcessRequest) of the appropriate IHttpHandler class for the request. For example, if the request is for a page, the current page instance handles the request.
  16. Raise the PostRequestHandlerExecute event.
  17. Raise the ReleaseRequestState event.
  18. Raise the PostReleaseRequestState event.
  19. Perform response filtering if the Filter property is defined.
  20. Raise the UpdateRequestCache event.
  21. Raise the PostUpdateRequestCache event.
  22. Raise the LogRequest event.
  23. Raise the PostLogRequest event.
  24. Raise the EndRequest event.
  25. Raise the PreSendRequestHeaders event.
  26. Raise the PreSendRequestContent event.
    NoteNote:
    The MapRequestHandlerLogRequest, and PostLogRequest events are supported only if the application is running in Integrated mode in IIS 7.0 and with the .NET Framework 3.0 or later.

What Is the Difference Between an ISAPI Server Extension and a Filter?

ISAPI Extentions
Runs when referenced in a URL. 
Is explicitly invoked, for example by http://myserver/myprog.dll?. 
Is loaded on demand, the first time a user calls it. 

ISAPI Filters
Is called for every URL the server processes.
Runs automatically for any URL sent to the server if the registered event occurs.
Is loaded when the service starts because of its registry entry.
Both server extensions and filters:

Share the process space of the service.
Must be thread safe.
Once loaded, remain in memory (until the service is stopped or the memory is needed by another process).

If you want to use custom ISAPI filter/extention you gonna write unmanaged code somehow. If its hard to code in more basic in IIS with c++,  you can use managed code  using c#,vb also IIS supports with .net framework and have similar structures at upper level (i mean using aspnet_isapi.dll) and you figure out that  ISAPI Filters are much like HttpModules and ISAPI Extentions are very like HttpHandlers .

See Also
http://msdn.microsoft.com/en-us/library/ax8e99d2(VS.71).aspx