using dll extention instead of the standard aspx - asp.net

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");
}

Related

url rewrite in asp.net for dynamially generated urls

I have few dinamically generated urls like http://localhost:35228/begineercontent?name=lanaguages&id=23, I used routing to hide .aspx extension and now i want to see above url like this http://localhost:35228/begineercontent/lanaguages/23 i tried few url rewrite methods from iis url rewrite tool nothing worked kindly please help me out
This can be done very easy. You need to change/add this code in your global.asax.
void registerroute(RouteCollection routes)
{
routes.MapPageRoute("begineercontent", "begineercontent/languages/{Id}", "~/begineercontent.aspx");
}
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
registerroute(RouteTable.Routes);
}
You also need to include the right assembly in global.asax by adding
using System.Web.Routing
In your begineercontent.aspx you need to add this code to the page load function.
var Id=( Page.RouteData.Values["Id"] as string);
A more detailled tutorial on how to work with routes can be found here:
http://msdn.microsoft.com/en-us/library/vstudio/cc668177%28v=vs.100%29.aspx

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:\");

Why does my WebClient request work differently depending on it's hosting solution?

In it's very basic form I have a WebClient request for some xml in a Page.xaml code behind. Something like:
public Page()
{
InitializeComponent();
Uri uri = new Uri("Dummy.xml", UriKind.Relative);
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(uri);
}
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
//Do something
}
}
If I setup my Silverlight project to run through an asp.net hosted page, and then put Dummy.xml in the ClientBin folder (relative to the xap) it works fine.
If I setup the project using just the automatically generated test page option, and again put the xml relative to the xap, the request doesn't work (although the completed event does fire).
My question is why? Is it a requirement that any Silverlight project that dynamically downloads has to be on a server?
Cheers
J
First up, try to avoid using the auto generated test page. It requires you to understand how the silverlight security by default model works when the xap is being accessed as a file.
To answer your question, you're encountering the security designed to prevent unauthorised cross-domain access.
Yes, there is no webserver for it to connect to! The autogenerated test page just opens that XAP directly without invoking Visual Studio's web server. If you want to do this you must use the other option to create a website with the silverlight project. Alternatively, you can embed the XML file in the XAP as a resource and access it as a resource.

Resources