indexing - C#/.NET Server Path to default/index page -


For a project ahead of future proof, I try to find the best way to recover the full path and filename The index / default page to be used without the information of the C # and Web server's file names in the web directory.

'Server.MapPath ("/ test /")' gives me 'C: \ www \ test \'

... also does this: 'server.mappath (Page. Risollul ("/ test /")) '

... but I need' c: \ www \ test \ index.html '

Is anyone aware of an existing method to retrieve the file name when a browser is browsing in that directory, the webserver will serve - default.aspx, or index.html,

ASP.NET has no knowledge of this IIS query for the default document list Will need to be

The reason is that by IIS IIS default document will appear in your Web Folders to the first matching file in the list to expand the file type in the mail script mappings matching Aisapiai (extension).

To get the default document list, you can do the following (using the default website as the IIS number = 1 example):

  using the system ; Using System.DirectoryServices; Namespace Console Application 1 {square} {static void Main (string [] Aarjijh) {(Nirdeshikaintrri W3svc = new Nirdeshikaintrri ( "IIS: // localhost / Dbluessvisi / 1 / root")) [{string] defaultDocs = w3svc.Properties [ DefaultDoc "] Value.ToString () split (',') ..}}  

Then to see what file exists in the file, defaultDocs There will be a case of reversing the array, the first match is the default document, for example:

  // Call me: string doc = GetDefaultDocument ( "/"); public String GetDefaultDocument (string Srhwarpath) {(DirectoryEntry w3svc = new Nirdeshikaintrri ( "IIS: // Sthaniyhost / W3SVC / 1 / root")) {string [] defaultDocs = w3svc.Properties [ " DefaultDoc "]. Value.ToString () to split (", "); string path = Server.MapPath (serverPath); Foreach (string default docs docName) {if (File.Exists (Path.Combine (path, docName ))) {Console.WriteLine ( "default dock:" + docName); return docName;}} // No matching default document did not return null; }}  

Unfortunately this will not work if you are partial trust in the ASP.NET environment (for example shared hosting).


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -