How do i block of page requests to the website , and make it unavailable (redirect to an error page) for a specific time slot?
You can place a file named app_offline.htm in the root directory of your ASP.NET website and ASP.NET will automatically route all traffic to this html page. In this file you can have any HTML code to show end user that maintenance is currently in process.
Other way of doing the same can be found Here
Insufficient info.But still you can use any of the methods. HTTHandlers in ASP.net Web forms Action Filters in ASP.net MVC. You can just check a flag set in Config file to determine whether to redirect or not if it needs to be configurable. Else you can check specific condition.
Related
currently we have our website running like this: websitename.com. But we've added multiple languages to it so now all the English content will be available at websitename.com/en and the Russian content will be available at websitename.com/ru. Google has already indexed the URLs at websitename.com. Now, I want to redirect these URLs to default en.
i.e. websitename.com/page1 to websitename.com/en/page1
How do I acheive this?
Redirection is one way to make sure that users always receive the Web
page that they want. Redirection refers to the process of configuring
the Web server to issue a redirect message to the client, such as HTTP
302, which instructs the client to resubmit the request for a new
location. You can redirect users to another file, directory, or site.
You can check MSDN article about IIS Redicrection. Check the links in Procedures section.
Here is the situation: there has been an application for years. It's old and should not be used. Therefore I created a whole new application to replace the other. Now I want to show a piece of information to the users trying to access the old one (regardless whether already authenticated or, which is more likely, not yet authenticated) and a link to the new one.
I don't want to change anything in the old one or just change as few things as possible, it should stay. So I came up with an idea: why not backing up current Default.aspx and then creating new Default.aspx telling users to try and use the new application (maybe slightly modifying web.config but how?). However, when an unauthenticated user enters ~/Default.aspx, she gets redirected to the login page.
Is it possible to allow unauthenticated users to see this default page without getting redirected to the login page just to give their credentials and then see the default page telling that there is the other application?
Are you just looking to "announce" that users should go to the "new" application (and not do an auto-redirect)?
IF SO, then wouldn't a simple html page that made this announcement be your "linker"?
The reason I'm suggesting .html (instead of an .aspx page) is that if you "don't want to change anything" in the old site, then an html page/file takes it out of the "ASP.Net pipeline" (asp.net will not process it, IIS will) - I'm guessing that the entire old application requires authentication because you mentioned the default.aspx (normally the default document of the web site/application) already requires a login (which is why it redirects).
You can set the "old" application default document to be this (new) standard "announcement" page.
Hth...
Well, there are many questions on SO which proves that you have the possibility to hold both ASP WebForms as well as ASP NET MVC Applications running together.
Note:
In MVC, What happens ? The short answer is Every requests to the webserver first goes through aURLRoutingModule object which reads the request and performs route-selection (depending upon global.asax file). The MvcRouteHandler then handles the controller method invocation.
That is okay.
All I am trying to understand is what happens when a user sends a request to the browser when the web server contains both Web-Forms as well as an ASP.NET MVC Application.
Who reads the URL and understands whether it is an .aspx extension or it is a request to mvc ?
How exactly the ISAPI.dll function in this case?
It's actually fairly simple: the URLRoutingModule checks the disk to see if there is a physical file which matches the current request URL. If there is a match, the Routing module assumes that it shouldn't run for this request, and ASP.NET's default behavior is then to look up and invoke the default handler for this extension. In the case of .aspx, that would be the Web Forms handler.
You can change this via the RouteCollection.RouteExistingFiles property in your RegisterRoutes method. This property controls whether the Routing module should intercept the request regardless of whether there is a physical file on the hard drive.
To understand better what happens when a user sends a request to the browser when the web server contains both Web-Forms as well as an ASP.NET MVC Application is by knowing on how ASP.Net runtime perform the Url routing which it is actually done by the ISAPI filter plugin.
Below are the detailed steps for Webform request:
1) When user enter a url like website1.com/page1.aspx in the browser.
2) Browser will send a Get Request to the IIS server asking for Page1.aspx file.
3) Then ISAPI filter is the first process to access the Http data before IIS can start to do anything. Here it act like a router for IIS request.
4) ISAPI filter will then check the url whether the filename has any extension (.aspx) and check whether the (.aspx) extension is mapped to the aspnet_isapi.dll or not.
5) If ".aspx" is mapped, it will invoke the ASP.net UrlRoutingModule and mapped the HttpHandler for ASP.net files.
For MVC request:
1) It follow the same step like webform request until the ISAPI filter found that there is no filename and file extension exist in the Url since MVC Url only contain the controller and action name.
2) All Url need to be mapped to a handler when the request initially received because routing will not work with unmanaged handler request
3) To direct this unmanaged request to managed code, it can be done by setting wildcard mapping to aspnet_isapi.dll for IIS6. For IIS7, we can just set the runAllManagedModulesForAllRequest="True".
4) Then only ASP.Net UrlRoutingModule will be invoked and try to match the Url with the application defined route.
5) If there is a match, it will direct to HttpHandler of Asp.net MVC framework. But if there is no match, the default Asp.net webform mapping will be used and most likely the request will return a HTTP 404 error result.
For more details you may refer to this web:
Mixing Web Forms and ASP.NET MVC
Web Server and ASP.NET Application Life Cycle in Depth
I am building a ASP.NET web application, the requirements are as following
when the user first lands on the website - dafult.aspx page , it should recognise the culture setting, if it is english it should retireve en\default.aspx
once the user lands on en\dafault.aspx page, the page has dropdown list to choose language, if the user chooses UK - English , it should redirect them to gb\default.aspx
my web site file structure is as follows
default.aspx
en/
default.aspx
gb/
default.aspx
fr/
default.aspx
es/
default.aspx
it/
default.aspx
nl/
default.aspx
Can you advise me how to achieve this with code samples?
I am pretty successful building localized website based on resource files, but we have specific requirement to build website in the above mentioned format.
You could use a global.asax hook. You would also need a flag for the current language selected by user. This could be the current culture's locale selected by the user or a flag stored on a cookie, or something else...
For example, you could use a hook function there, for example Application_BeginRequest where you could decide where to redirect the current request. If your current locale is it then you could parse the requested URL and redirect to the specific folder.
Just to be clear, I would not suggest following this approach overall. I would strongly suggest following the suggested by microsoft localization process. The approach I describe above is not very clean and I believe it is not as fast as the embedded solution proposed by microsoft.
Hope I helped!
I have a subdomain that is http://trade.businessbazaar.in . I am dynamically creating urls from database something in this manner http://trade.businessbazaar.in/mycompany. To display details, I have an index.aspx file there,thinking that on every request the index.aspx page will load and display data accodingly. Also, There is a masterpage on the index.aspx page from where i am capturing the text mycompany and query it in database to fetch result. But nothing seems to work.
A genuine link is http://trade.businessbazaar.in/Symparlife. But its unable to load index.aspx. I need a clean approach without any third party dll or rewriters. Directly to push some lines in config and start working. That is url will be the same but index page will get loaded...
In short, i want to say
I need the StackOverflow type clean url mechanism to fetch pages
Thanks in Advance
You can handle the Begin_Request event in Global.asax and add custom code to redirect to index.aspx and convert the parts of the URL into query string arguments. You should use Server.Transfer to keep the URL in the browser.
I'd recommend upgrading to 4.0 and using the Routing enine though. You should check if the standard routing is available as a download for ASP.NET 3.5. I am sure your code will get messy very soon. Been there, done that.
As #Mike Miller mentions in the comments the Routing engine ships with ASP.NET 3.5. You can check the documentation here - http://msdn.microsoft.com/en-us/library/system.web.routing(v=vs.90).aspx
Here is a tutorial on how to use it with Web Forms - http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx
For your case the code would be something like:
routes.MapPageRoute("company-index", "/{company}", "~/index.aspx")
And in index.aspx you can access the route value for company like this:
string company = (string)Page.RouteData.Values["company"];
Keep in mind that you'd better add something in the URL before your actual argument (the company name). If you don't you will have problems later on when because you may want to add a URL like "/Login" but then you will have to validate that users can't create a company named "Login". Not how Stack Overflow has "/questions/" before the actual question info in the URL.