I have a webmail and i want the user to press on a picture in the webmail and then be linked back to my mvc project view. I don't have a real domain yet so i can't type www.mysite.com. I want to be able to link to the view without depending on which domain the site is currently running on.
in my webmail i have the body that looks like this:
string Body = "<b>Välj ett alternativ!</b><br><br><a href='cid:path4'/><img src='cid:Happy'/ alt='HTML tutorial' width='120' height='120'></a><input type='image' src='cid:Orange'/ name='image' width='120' height='120'><input type='image' src='cid:Mad'/ name='image' width='120' height='120'>";
where the cid:path4 is i want the url och what ever so that i linkes me back to my project.
You'll have to format the absolute path into the body text from your controller action (or pass it through to whatever method generates the body):
var path = Request.Uri.AbsoluteUri;
var emailBody = String.Format("Your email body. Link", path);
Or, you could link to another controller action with Url.Action:
var path = Url.Action("MyAction", "MyController", null, "http");
var emailBody = String.Format("Your email body. Link", path);
Of course, this all assumes that this email is sent by a controller action - if it's not, it may not be possible to determine the absolute URI of the website.
Related
My scenario is very simple.
I have an Overview page where i can create a layout.
I have an Add page where i can enter essentials.
I have an Edit page where i can manipulate specifics
My MasterLayout has a back button which utilizes HttpContext.Request.Headers["Referer"]
The screenshot is on the Add page.
When i add my Layout i want to alter the Referer, so when i get forwarded to ./Edit the referrer should be set to another page, instead of ./Add - for the sake of the example google, but in reality it should be the Overview page.
Do i need to write custom middleware for this?
update:
this does not work - the url works, but adding the referer like that does not.
var linkGenerator = HttpContext.RequestServices.GetService<LinkGenerator>();
var url = linkGenerator.GetPathByPage("/LayoutEngine/Administration/Overview");
HttpContext.Response.Headers.Add("Referer", url);
HttpContext.Request.Headers["Referer"] = url;
HTTP headers are valid only for the current response. When you set a redirect the current response contains your custom header but when the browser follows the redirect location those headers are no longer present, you need to sent the Overview value as query string to the Editpage:
.........
var url = linkGenerator.GetPathByPage("/LayoutEngine/Administration/Overview");
.........
return RedirectToPage("./Edit", new{id = result.Result, returnUrl = url});
I stored image file in path djangor_prject_name/pictures/image_name.jpg by using
models.ImageField(upload_to='pictures/services/', max_length=255, null=True, blank=True)
and file is uploaded successfully.
But while retrieving, what is the exact url to view image?
Because id Database, the value is just
picutes/services/image_name.jpg
So, in my view file, I am using vue.js and need full path or url of the image to display.
After creation it won't give you full url, but in the list it will come with full url. So for that you use custom serializers.SerializerMethodField.
class TestSerializer(serializers.ModelSerializer):
photo = serializers.SerializerMethodField()
class Meta:
model = Test
fields = ('photo',)
def get_photo(self, car):
request = self.context.get('request')
photo = Test.photo.url
return request.build_absolute_uri(photo)
For further details refer here
I've read the tutorials to log into a website prior to scraping it, but it just ain't workin'. I constructed a HttpIdentity object, added it to the Identities collection, and processed the request, but the page returned to scrape was still the login page. There isn't a lot about this on their website and documentation. Here's my code for that:
var identity = new HttpIdentity
{
UseCookies = true,
NetworkUsername = _username,
NetworkPassword = _password
};
Identities.Add(identity);
Request(_uri, Parse, identity);
In the Parse method I get a Response object returned with a Status Code of 200, and the "WasSuccessful" property of Response is "true". It seems that I should be redirected to the page I was trying to access, but I'm just getting the login html.
Is there something I'm missing?
I wasn't able to find a solution using the Iron Web Scraper, but I was able to do it with ScrapySharp, which is a free utility, so it worked out. ScrapySharp is able to mimic a browser to a degree, so navigation and submitting forms is pretty easy.
var browser = new ScrapingBrowser();
var homepage = browser.NavigateToPage(_Uri); // login Uri
var form = homepage.FindForm("login"); // get form by name
form.Method = HttpVerb.Post;
form["username"] = "my_username"; // get form fields by id
form["password"] = "my_password";
var resultPage = form.Submit(); // login
var loggedInPage = browser.NavigateToPage(new Uri("https://path.to.target.page"));
And that's it. I'm not sure what the problem was with Iron Web Scraper. Maybe some ajax on the login page. In any case, this code is working for me now.
I am working on an MVC 4 web application. On one page I am providing an anchor link which refers to a file on application's directory. The code of the same is -
#Html.Action("Download_Static_File", "Charge_Entry", new { File_Path = "../../Content/Templates/Pt_Data/Pt_Data.xls", File_Name = "Pt_Data_Template", value = "Download template" });
My motive is that the file should be downloaded on click.
However when I click the link, I get an error like
Could not find a part of the path 'C:\Program Files\Common Files\Microsoft Shared\Content\Templates\Pt_Data\Pt_Data.xls'.'
I also tried
System.Web.HttpContext.Current.Server.MapPath
which is giving this error:
OutputStream is not available when a custom TextWriter is used.
The action method being called is:
public FileResult Download_Static_File(string File_Path,string File_Name)
{
byte[] fileBytes = System.IO.File.ReadAllBytes(File_Path);
return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, File_Name);
}
Is it the correct approach? Any help will be appreciated.
I also referred this link
Your anchor seem to be pointing to a controller action named Download_Static_File (which unfortunately you haven't shown) and passing a parameter called File_Path.
The #Html.Action helper that you are using in your view is attempting to execute the specified action as a child action. You may find the following blog post useful which describes child actions: http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx/
I guess that what you are trying to achieve is to generate an anchor in your view pointing to the static file which can be downloaded by the user. In this case you'd rather use an anchor tag in conjunction with the Url.Action helper:
<a href="#Url.Content("~/Content/Templates/Pt_Data/Pt_Data.xls")">
Download_Static_File
</a>
This assumes that your web application has a folder called Content/Templates/Pt_Data under the root containing a file named Pt_Data.xls which will be downloaded by the user when he clicks upon this anchor tag.
If on the other hand the file that you want to be downloaded by the user is situated in a folder which is not publicly accessible from the client (for example the ~/App_Data folder) you might in this case have a controller action on your server that will stream the file:
public ActionResult DownloadStaticFile(string filename)
{
string path = Server.MapPath("~/App_Data");
string file = Path.Combine(path, filename);
file = Path.GetFullPath(file);
if (!file.StartsWith(path))
{
throw new HttpException(403, "Forbidden");
}
return File(file, "application/pdf");
}
and then in your view you would have an anchor to this controller action:
#Html.ActionLink(
linkText: "Download template",
actionName: "DownloadStaticFile",
controllerName: "Charge_Entry",
routeValues: new { filename = "Pt_Data.xls" },
htmlAttributes: null
)
Im trying to post an activity with an image to a google+ domain with the new google + domains API
Posting an activity is working fine but when i try to attach a photo to it, i receive a 500 error with null description.
This is the code:
String msg = "Activity with photo";
// Create a list of ACL entries
PlusAclentryResource resource = new PlusAclentryResource();
resource.setType("domain"); // Share to domain
List<PlusAclentryResource> aclEntries = new ArrayList<PlusAclentryResource>();
aclEntries.add(resource);
Acl acl = new Acl();
acl.setItems(aclEntries);
acl.setDomainRestricted(true); // Required, this does the domain restriction
// Create a new activity object
Activity activity = new Activity()
.setObject(new Activity.PlusObject().setOriginalContent(msg))
.setAccess(acl);
// Attach the link
Activity.PlusObject.Attachments attachment = new Activity.PlusObject.Attachments();
attachment.setObjectType("photo");
attachment.setUrl( "http://c299813.r13.cf1.rackcdn.com/MuseeduLouvre_1335428699_org.jpg" );
attachment.setId( randomId ); //if not specified, google returns an error with "you must specify the photo id"
List<Activity.PlusObject.Attachments> attachments = new ArrayList();
attachments.add(attachment); // You can also add multiple attachments to the post
activity.getObject().setAttachments(attachments);
activity = plus.activities().insert("me", activity).execute();
When the code calls the execute, i receive this error:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 500
{
"code": 500,
"message": null
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
The same code but with the attachemnt lines commented works fine. Has someone managed to create an activity with an image? any clue?
Thanks in advance.
Directly attaching a photo via URL isn't possible. The process works slightly differently, as described here: https://developers.google.com/+/domains/posts/attaching-media
If you don't have the actual binary data of the photo you will first have to "download" the photo. Then you can upload the actual photo data via the media().insert method, which will give you the Photo Id which you can then use in attachment.setId().
setUrl isn't necessary in this case.
If you want to attach a photo as URL, this could also be handled like an article attachment (same as if you would just copy/paste the URL into a Google+ post). In that case you would use attachment.setObjectType("article") and only set the Url. The id isn't necessary in this case.