MVC Deployment resource URLS not resolving - c#-4.0

My URLs aren't resolving correctly.
When I deploy my app name is omitted from the urls.
Its suppose to be:
http:////Content/images/ect
But it gets rendered as
http:///Content/images/ect
which obviously doesn't resolve.
My URLS looks like this:
<img src="/Content/images/Misc/Lock.png" />
If I add a ~ to the url (before content) it resolves perfectly when deployed, but breaks in my dev environment.
This being a MVC app means I also have a few ajax calls to actions (controller/action/) which also does not resolve, breaking most of the site.
I deployed under the default web site in IIS, moving it to another site is not an option.
Any advice will be greatly appreciated.

Have you tried using Url.Content?
It would be something like this (untested)
<img src="#Url.Content("~/Content/images/Misc/Lock.png")" />

This has to do with your host, if you are running this site as a sub site and not under its own IIS site, the host requires the ~. I have gotten around this by using a global javascript variable to hold the site root. I populate the variable in the main site layout like so:
var gSiteRoot = '#MvcHtmlString.Create(Url.Content("~/"))';
Then when I need to construct a url in js I use it like so:
var url = gSiteRoot + 'restofurl';

Related

Swashbuckle running with katana-owin based web api doesnt work with IIS but works with IIS Express

I think I have a similar issue as this post-
Webactivator doesn't run on IIS 7
Swashbuckle running with katana-owin based web api is able to work with IIS Express.
assume all the urls below have an "http" prefix.
I can browse to something like localhost:8085/swagger Which redirects me correctly to localhost:8085/swagger/ui/index
But when published to IIS redirects to localhost/swagger/ui/index instead of localhost/myapp/swagger/ui/index and this results in a 404. Notice that even though an application name is specified while publishing somehow swashbuckle/swagger doesn't know and only uses the pathbase without the application name.
basically it just picks up the site root URL instead of the application URL that was used to call /swagger
Any solution to this problem?
I got the same issue. Solved this using the following code (c.RootUrl)
config.EnableSwagger(c =>
{
c.IncludeXmlComments(GetXmlCommentsPath());
c.SingleApiVersion("v1", "yourAPI");
c.RootUrl(req => req.RequestUri.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/").TrimEnd('/'));
});
Reference : Relative path for UI request URL

Nancy on Owin doesn't serve static content

I'm running self hosted Nancy web application on Owin and have troubles with static content.
Let's say my application runs from this folder:
c:/myfolder/
My Views are in here:
c:/myfolder/Manager/Views/
so in my browser I can go to http://localhost:85/Manager and my page loads.
I simply can't make it to serve static content though, all my files are in /Content folder, I tried to place it both to /myfolder and /Manager folder with no luck.
Neither http://localhost:85/Manager/Content/css/styles.css nor http://localhost:85/Content/css/styles.css urls work
How do I get it to work?
Fixed the problem by adding these lines of code to Startup :
using Microsoft.Owin.FileSystems;
using Microsoft.Owin.StaticFiles;
...
var options = new FileServerOptions()
{
RequestPath = PathString.Empty,
FileSystem = new PhysicalFileSystem("/Path/here")
};
app.UseFileServer(options);

Serve out swagger-ui from nodejs/express project

I would like to use the swagger-ui dist 'as-is'...well almost as-is.
Pulled down the latest release from github (2.0.24) and stuck it in a folder in my app. I then server it out statically with express:
app.use('/swagger', express.static('./node_modules/swagger-ui/dist'));
That works as expected when I go to:
https://mydomain.com/swagger
However I want to populate the url field to my swagger json dynamically. IE I may deploy to different domains:
https://mydomain.com/api-docs
https://otherdomain.com/api-docs
And when I visit:
https://mydomain.com/swagger
https://otherdomain.com/swagger
I would like to dynamically set the url.
Is that possible?
Assuming the /api-docs (or swagger.json) are always on the same path, and only the domain changes, you can set the url parameter of the SwaggerUi object to "/path/to/api-docs" or "/path/to/swagger.json"instead of a full URL. That would make the UI load that path as relative to the domain the UI is hosted on.
For reference, I'm leaving the original answer as well, as it may prove useful in some cases.
You can use the url parameter to set the URL the UI should load.
That is, if you're hosting it under https://mydomain.com/swagger you can use https://mydomain.com/swagger?url=https://mydomain.com/api-docs and https://mydomain.com/swagger?https://otherdomain.com/api-docs to point at the different locations.
However, as far as I know, this functionality is only available at the current alpha version (which should be stable enough) and not with 2.0.24 that you use (though it's worth testing).
Another method would be to use the swagger-ui middleware located in the swagger-tool.
let swaggerUi = require('../node_modules/swagger-tools/middleware/swagger-ui');
app.use(swaggerUi(config.swagger));
The variable config.swagger contains the swagger.yaml or swagger.json. I have in my setting
let config = {
appRoot: __dirname,
swagger: require('./api/swagger/swagger.js')
};
Note: I am using the require('swagger-express-mw') module
You could try with this on index.html file of the swagger-ui... It works for me.
if (url && url.length > 1) {
url = decodeURIComponent(url[1]);
} else {
url = window.location.origin + "/path/to/swagger.json";
}

Is it possible to change default sharepoint 2013 app url

The default app url looks like http://[app prefix]-[app id].[domain name]/[site collection path]/[app path]/pages/default.aspx.
It is unconvinient because every deployment during development generates new url. And after development stage the end users need a permanent link to the application, but every bug fixes or updates that will be deployed will cause new app url generation. Is there right way to fix the app url?
You can create a URL controller:
Create a list that would contain two fields: fakeUrl, realUrl,
fakeUrl can be something like "http://staticappname.[domain name]/[site collection path]/[app path]/pages/default.aspx"
realUrl would be your http://[app prefix]-[app id].[domain name]/[site collection path]/[app path]/pages/default.aspx
Give your users fakeUrl
Create a HTTPModule that would read the list and redirect the http request to the realUrl
After you redeploy your app, just change the realUrl in the list
***I'm not if this is your case but you could change your app to be a provider-hosted. Then you would get a static Url
You can open your SharePoint hosted add-in using an alternate link like:
http://[SharePointSite]/[Add-inName]
For eg.
http://contoso.com/sharepointhostedapp/

SPWeb.ApplyWebTemplate() method - delay issue

I have a custom site definition and in the provisioning handler I am using SPWeb.ApplyWebTemplate("My site defintion name") to apply the site definition. It works fine but i have observed that there is some delay in applying the web template.
What i did is that in the onet of my site defintion i have set the masterurl attribute to /_catalogs/masterpage/MyMaster.master. Now if i create a site under sites folder using this site definition, the sites gest create successfully but on browsing it throws the error as "resource cannot be found". I did some investigation and came to know that the master url should be server relative and not the site relative. So in the provisioning code after applying the template i write the code to update the master URL by prepending Site's server relative URL to it.
Web.MasterUrl = Site.ServerRelativeUrl + Web.MasterUrl;
But when i browse the site it did not work and i got the same error. I debugged the code and found that the even after applying the template the master URL is set to default.master. I waited there on that statement in the debug mode and found that after some time (some secs) the master URL changed to the URL which i set in the onet i.e MyMaster.master.
So looks like ApplyWebTemplate() is an asynchronous method. How can I be assure that the applying web template process is finished.
Thanks.
You could try getting a new spWeb object for the site after the call and check the Template property.

Resources