getting back to folder in asp.net - asp.net

protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Page2.aspx");
}
this is code to go on .aspx but what if i want to go in Folder in my solution explorer, tried with location but it dont work
Who knows post it.
this is location >
website\admin
-news.aspx
-project.aspx
and i created in news.aspx button go back to admin, and when i hit button location is next > website\admin\admin why he duplicate admin ?

Response.Redirect("~/Folder/Page.aspx");
The tilde ~ is very useful for redirects, it signifies your site root. So wherever you are on the site, you can redirect to folders relative to the domain root. I hope this is what you meant!

if you have admin folder in your application then redirect it
Response.Redirect("admin/page.aspx"); or
Response.Redirect("~/admin/page.aspx");
if you don't have admin folder in your application then redirect it
Response.Redirect("page.aspx");
Try this all ...

Related

How to remove folder name from URL in asp .net

Hi I have just shifted my website to new hosting parter with multiple website hosting plan. Every things are working fine except one issue with url. As for different websites there are diffrent folders where i upload my website files these will cause url issues. like :
My previous URL : www.abc.com
After uploading www.abc.com/folderName So I would like to remove folderName from the url. I have googled to many documents regarding web.config url rewrites but none of them are working. Kindly help to remove folderName from the URL. (Note I am also using URL Routing in global.asax if possible to remove folder name using global.asax it will work for me too)
Thanks
I have solved my issue by following steps
1) Used Global.asax to forefully redirect my users to my website without folder name.
protected void Application_BeginRequest(object sender, EventArgs e)
{
Response.RedirectPermanent("http://www.myDomain.com");
}
2) I have changed my relative URLs to Absolute URLs
Changed ~/contact to http://www.myDomain.com/contact

Adding Cache headers via a Web.config for specific locations only

We have an application that has been developed by the third party, and I don't want to go back to them to get them to add in cache control for specific pages.
All the pages that need caching disabled are in a single directory.
The issue is that IE seems to not follow Cache-control:nocache properly, so we need to add in Pragma:nocache and cache age as well.
Is there a way to do this using configs in the directory? will it cascade through all child directories? Can it be done via the main web.config?
To be clear, I'm not looking for a way to do this via code, it needs to be via configuration of either IIS or the web.config files.
We're using ASP.NET 2.0 and 4.0, on IIS 6.0.
This can be done in IIS using the UI, it's actually quite easy, or atleast it was in my use case.
All you do is simply open up IIS manager, navigate to the site and then the directory you want to add the headers to Right Click -> properties.
Click the "Headers" tab, and add in the headers you require.
This goes recursively down the child directories, and adds the headers before any added by the code.
In IIS 7.0/7.5, you can use the StaticContent section of a web.config in each of the directories.
You can do that on global.asax
protected void Application_BeginRequest(Object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
string cTheFile = HttpContext.Current.Request.Path;
if (cTheFile.Contains("/ExtraDir/"))
{
// add your header here
app.Response.AppendHeader("Pragma", "no-cache");
}
//... rest code of...
}

How to open folder from web page

I want to open folder from web page on clicking on a button.
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("file://C://inetpub//wwwroot//myproject");
}
Please suggest me proper code in C# for open myproject folder.
This can be ONLY done in IE, no other browser has access to file system. You can assign the path to href of an anchor tag, and it should work.
Open
If you're looking at adding functionality to your website so that a user can upload files to it then look at this project on MSDN. It'll show you how to do this with an example ASP.NET project.
Maybe this statement can help you:
System.Diagnostics.Process.Start(#"C:\");

using dll extention instead of the standard aspx

I am replacing an existing web application, that all it's requests go through a url:
www.something.com/scripts/xxx.dll?args
I created my own aspx page that handles these requests and it is called:
www.something.com/scripts/xxx.aspx?args
My problem is that there are many existing links, from other website that refer to the xxx.dll?args url.
Can I create my own dll in .net that will receive the xxx.dll?args requests and process them?
This isn't a simple redirect, because I also need the args
I'd suggest to rather use Url Rewriting
After some more investigation I did the following.
Change the web.config, to make sure all requests go through my code by adding the following code:
...<system.webServer>
<modules runAllManagedModulesForAllRequests="true">...
Added a global.asax file to the web project, and within it wrote the following code:
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Request.Path.EndsWith("xxx.dll",
StringComparison.InvariantCultureIgnoreCase))
Context.RewritePath("/scripts/xxx.aspx");
}

asp.net site default document in subfolder

My default document is in subfolder not in root how can i make it default in asp.net 2.0 website.
Tried iis7 default document setting to '/pages/default.aspx'
'~/pages/default.aspx' but it didn't work.
Default document is not the same as start page. Default document means if I requested mysite.com/somefolder and didn't specify a file, which file should IIS display.
If you want to use a specific page as your home page, create a Default.aspx file and write this in it's codebehind class:
public override void ProcessRequest(HttpContext context) {
context.Response.Redirect("pages/default.aspx", true);
}
As the client might have disabled Javascript, a server side approach would be more reliable. However it's best to issue a permanent redirect instead of a simple Response.Redirect. Also doing it using JS will be bad from a SEO point of view.
You don't need to create a dummy Default.aspx page.
In your Global.asax.cs file, write the following:
public void Application_Start(object sender, EventArgs e)
{
var routeCollection = RouteTable.Routes;
routeCollection.MapPageRoute("DefaultRoute", string.Empty, "~/YourDesiredSubFolder/YourDesiredDocument.aspx");
}
Explanation:
Application_Start code is guaranteed to run once and only once on the application start.
The first line of code, gets a collection of the URL routes for your application.
The second line of code, defines a new route pointing to your inner page in the subfolder that you wish.
The second argument is empty to indicate that this route is used when there's no specific page is requested and there's no Default document existing.
Default documents are a subfolder-specific thing - what you're trying to do won't (directly) work. Set up a default.htm file in the root, and have it refresh to your real "home page".
The better question you should be asking is how on Earth your homepage got out of the root directory.
In theory you could have a Web.config file inside the directory and use the defaultDocument element to set the default document. See here: https://stackoverflow.com/a/2012079/125938.
Unfortunately I haven't been able to get it to work myself locally, but that might be because it isn't supported in the Visual Studio development server.
Say "index.html" is the default page you want and it is present in "Public" subfolder.
Instead of specifying "/Public/index.html" as the default site, try "Public/index.html"

Resources