asp.net mvc - Calls for files are made in the wrong file path -
hi trying build angular app , have following situation in asp.net mvc. have created app folder in root directory of project contains following:
- styles folder
- scripts folder
- images folder
- index.html file
then instead of returning view in homecontroller index action returned following:
public actionresult index() { return file(server.mappath("/app/index.html"), "text/html"); }
the index.html has following style added:
<link rel="stylesheet" href="styles/main.css">
when run app index.html gets retrieved error inside of retrieving style file:
http://localhost:57826/styles/main.css
for reason instead of looking in the following path http://localhost:57826/app/styles/main.css
looks in path mentioned above.
i tryed intercept calls , files correct path creating custom router this:
routes.maproute( name: "style", url: "styles/{*path}", defaults: new { controller = "www", action = "style" } ); public class wwwcontroller : controller { public actionresult style(string path) { byte[] content = this.getcontent(this.correctpath(path, "css")); var result = new filecontentresult(content, this.getcontenttypefor(path)); return result; } private string correctpath(string path, string folder) { return server.mappath("/app/" + folder + "/" + path); } private byte[] getcontent(string path) { byte[] readallbytes = system.io.file.readallbytes(path); return readallbytes; } private string getcontenttypefor(string path) { return system.web.mimemapping.getmimemapping(path.getfilename(path)); } }
but solution not seem work.the style action not called.can tell me how can solve problem
why breaking mvc model not allowing view presentation work? this:
public actionresult index() { return view(); }
then put whatever content need views/home/index.cshtml:
<link rel="stylesheet" href="styles/main.css"> @* add link tags, javascript, etc. *@
or use vanilla asp.net site.
Comments
Post a Comment