Unable to read query string in VB.NET web application - asp.net-mvc

I have vb.net website and MVC 4 application. I am sending the query string from MVC application to VB application. The VB.Net application is hosted in IIS server.
Temporarily I am reading the query string on a label. The problem is that during first click the query-string doesn't get read. But during the second click on the same link, the query string gets printed on the label.
MVC code:
public JsonResult OpenK3oneWebLink(string strLinkName)
{
string strWebLink = string.Empty;
string linkName = string.Empty;
try
{
if (pclsConcurrency.UXControllerServiceClient.modifyUserStatus("T", pclsConcurrency.strUsersId) == true)
{
string[] arr = pclsConcurrency.m_strDBName.Split('_');
string DBNameForUrl;
if (arr.Length == 1)
{
DBNameForUrl = arr[0];
}
else
{
DBNameForUrl = arr[1];
}
eif (strLinkName == "daytoday")
{
strWebLink = "http://" + pclsConcurrency.m_strAppServer + "/K3OneWeb_" + DBNameForUrl + "/Environment/Login.aspx?intEntityId=" + pclsConcurrency.intEntityId + "&Users=" + pclsConcurrency.strUsersId;// +"192.168.0.163/K3OneWeb_aish1/Environment/Login.aspx?intEntityId=5&Users=SHG";
}
else if (strLinkName == "Daily")
{
strWebLink = "http://" + pclsConcurrency.m_strAppServer + "/K3OneWeb_" + DBNameForUrl + "/Environment/Login.aspx?intEntityId=" + pclsConcurrency.intEntityId + "&Users=" + pclsConcurrency.strUsersId + "&linkname=Daily";
}
and the vb.net code is
Label1.Text = Request.QueryString("intEntityId")
Label2.Text = Request.QueryString("Users")
Label3.Text = Request.QueryString("linkname")
it is written on page load event but, unable to retrieve it on the first click but get retrieved on the second click on the same link.The VB application is hosted on IIS server and MVC application is running locally.
TIA

Related

Google oauth2 works fine in localhost but not works in domain

I am trying to integrated Google Calendar Integration to my web site. Everything run on local host is perfect. But when I publish it in to domain it give me some error.
This bt.mypage.kr page can’t be foundNo webpage was found for the web
address:
http://bt.mypage.kr/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/calendar+https://www.googleapis.com/auth/calendar.events&access_type=online&include_granted_scopes=true&response_type=code&state=state_parameter_passthrough_value&redirect_uri=http://bt.mypage.kr/Schedule/UI/oauth2callback&client_id=myclientid
My code some thing like this:
public ActionResult AuthRedirect()
{
var url = "http://" + Request.Host;
sting redirect_uri = url + "/Schedule/UI/oauth2callback"
GoogleParram gpr = new GoogleParram(url);
string rerectUrl = "https://accounts.google.com/o/oauth2/v2/auth?" +
"scope=https://www.googleapis.com/auth/calendar+https://www.googleapis.com/auth/calendar.events&" +
"access_type=online&" +
"include_granted_scopes=true&" +
"response_type=code&" +
"state=state_parameter_passthrough_value&" +
"redirect_uri=" + url + "/Schedule/UI/oauth2callback&" +
"client_id=" + gpr.client_id;
return Redirect(rerectUrl);
}
public void oauth2callback(string code, string error, string state)
{
if (string.IsNullOrWhiteSpace(error))
{
this.GetTokens(code);
}
}
public IActionResult GetTokens(string code)
{
var url = "http://" + Request.Host;
GoogleParram gpr = new GoogleParram(url);
var request = new RestRequest();
request.AddQueryParameter("client_id", gpr.client_id);
request.AddQueryParameter("client_secret", gpr.client_secret);
request.AddQueryParameter("code", code);
request.AddQueryParameter("grant_type", "authorization_code");
request.AddQueryParameter("redirect_uri", url + "/Schedule/UI/oauth2callback&");
RestClient restClient = new RestClient(gpr.token_uri);
var response = restClient.Post(request);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
gpr.WriteToken(response.Content);
return RedirectToAction("Calendar");
}
return RedirectToAction("Calendar");
}
My Credentials
I hope anybody knows how to solve. Bundle of Thanks in advance.

Why is Outlook Interop opens outlook on my Pc even though some one else is accessing the link on their PC

I have created a function to share feedback with Agents who handled the Chats from Customer.
Feedback needs to be shared by Email from outlook. I tested the code and it does work great on my local PC.
Issue comes when some one else opens the WebApp on their local PC, and audit the Chat.
Some one else auditing chat on their Local PC opens Outlook to share feedback on my PC instead of opening on their own PC.
Can some one please help with the below code, and help me understand what is causing this to happen?
And, How can I resolve this?
Feedback Action method
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ShareFeedback(Chat model)
{
int id = model.ChatId;
var q1yes = "30";
var q1no = "0";
var q2yes = "10";
var q2no = "0";
var q3yes = "25";
var q3no = "0";
var q4yes = "35";
var q4no = "0";
if (!ModelState.IsValid)
{
return View(model);
}
int dtoId;
using (Db db = new Db())
{
Chat dto = db.Chats.Where(x => x.ChatId == id).FirstOrDefault();
dto.Feedback = model.Feedback;
dto.FeedbackDateTime = DateTime.Now;
if(model.Question1 == "Yes")
{
dto.Question1 = q1yes;
}
else
{
dto.Question1 = q1no;
}
if (model.Question2 == "Yes")
{
dto.Question2 = q2yes;
}
else
{
dto.Question2 = q2no;
}
if (model.Question3 == "Yes")
{
dto.Question3 = q3yes;
}
else
{
dto.Question3 = q3no;
}
if (model.Question4 == "Yes")
{
dto.Question4 = q4yes;
}
else
{
dto.Question4 = q4no;
}
dto.ErrorGrade = model.ErrorGrade;
if (model.ErrorGrade == "Low")
{
float total = float.Parse(dto.Question1) + float.Parse(dto.Question2) + float.Parse(dto.Question3) + float.Parse(dto.Question4);
dto.QualityScore = total;
}
if (model.ErrorGrade == "Medium")
{
float total = float.Parse(dto.Question1) + float.Parse(dto.Question2) + float.Parse(dto.Question3) + float.Parse(dto.Question4);
float medtotal = total / 2;
dto.QualityScore = medtotal;
}
if (model.ErrorGrade == "High")
{
float total = 00;
dto.QualityScore = total;
}
if(model.ErrorGrade == null)
{
float total = float.Parse(dto.Question1) + float.Parse(dto.Question2) + float.Parse(dto.Question3) + float.Parse(dto.Question4);
dto.QualityScore = total;
}
var uName = User.Identity.Name;
User userDTO = db.Users.Where(x => x.Username == uName).FirstOrDefault();
dto.FeedbackSharedBy = userDTO.Username;
dto.AuditorEmail = userDTO.Email;
db.SaveChanges();
dtoId = dto.ChatId;
}
using (Db db = new Db())
{
Chat dto = db.Chats.Find(dtoId);
Application app = new Application();
MailItem mailItem = app.CreateItem(OlItemType.olMailItem);
if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
{
mailItem.Subject = "Feedback: Chat handled on " + dto.ChatCreateDateTime + " For Customer " + dto.CustName;
mailItem.To = dto.Email;
mailItem.CC = "saurabhwa#cybage.com;sagargo#cybage.com;anacletem#cybage.com;riyazsh#cybage.com";
mailItem.HTMLBody = "Hello " + dto.FirstName + "<br /><br />" + " <b>Res Time:</b> " + string.Format("<b>{0:hh\\:mm\\:ss}</b>", dto.ChatEndDateTime - dto.ChatStartDateTime)
+ " <b>AHT:</b> " + string.Format("<b>{0:hh\\:mm\\:ss}</b>", dto.ChatEndDateTime - dto.ChatCreateDateTime) + " <b>Promptness:</b> " + string.Format("<b>{0:hh\\:mm\\:ss}</b>", dto.ChatCreateDateTime - dto.ChatStartDateTime) + "<br/><br/>" + "Your score for this Chat audit is : " + "<b>" + dto.QualityScore + "%</b>" + "<br /><br />" + "<b>Feedback:</b>" + "<br /><br />" + dto.Feedback;
mailItem.Importance = OlImportance.olImportanceHigh;
mailItem.Display(false);
}
}
return RedirectToAction("StartQMS");
}
Help is much appreciated.
Well, of course, your code is executed on your server, not on the client machine.
Besides the fact that you are using Outlook from a Windows service (IIS), which is a big no-no, you need to run the code on the client side, e.g. from a Java script in a page served by your server to the client browser.
And you cannot use Outlook from JS, unless you are running in IE, and your site is trusted. The best you can do is provide the user with a "mailto:" link that can pop up a new email window with the pre-populated subject, body, and recipients.

Wants to save Image of my user on 2nd sever MVC

I am currently working on a project in which we want to store image on separate sever. I don't now how to connect both the server so that i can easily save image on remote server.
if (Request.Files.AllKeys.Any())
{
foreach (string fileName in Request.Files)
{
HttpPostedFileBase file = Request.Files[fileName];
string oldFileName = file.FileName;
NewFileName = Guid.NewGuid().ToString();
string FileExtention = oldFileName.Substring(oldFileName.LastIndexOf('.') + 1);
if (FileExtention == "blob")
{
FileExtention = "jpg";
}
NewFileName = NewFileName + "." + FileExtention;
var fileSavePath = Path.Combine(Server.MapPath("~" + filePath + "Document"), file.FileName.Replace(oldFileName, NewFileName));
file.SaveAs(fileSavePath);
VisitDocument document = new VisitDocument();
document.VisitId = vid;
document.Title = oldFileName.Substring(0, oldFileName.LastIndexOf('.'));
document.RefPath = (filePath + "Document/" + NewFileName).Replace("/", #"\").Substring(1);
document.CreatedBy = tempUser.UserId;
document.CreatedOn = DateTime.Now;
document.IsDeleted = 0;
dal.VisitDocuments.Add(document);
dal.SaveChanges();
}
}
You have two options to do:
1- Use Web API application to do this task and deploy it on the server you want.
2- Open connection on the server and save the file there but you need to have account on this server and this account has the privileges to write and read.
string path = #"\\xxx.xxx.xxx.xxx\Uploads\"; // server IP
if (!System.IO.Directory.Exists(serverPath))
System.IO.Directory.CreateDirectory(path );
file.SaveAs(path + FileName);

ASP MVC Return SP result to View

Using VS 2013 and writing my first ASP MVC app. I have a controller:
// GET: CreateBundlesAndCartons
public ActionResult CreateBandC(Int32 id)
{
string ReturnMessage;
ReturnMessage = "";
using (SqlConnection connection = new SqlConnection())
{
//string connectionStringName = this.DataWorkspace.CooperData.Details.Name;
connection.ConnectionString =
ConfigurationManager.ConnectionStrings["PSAContext"].ConnectionString;
string procedure = "PSA.dbo.CreateBundlesAndCartons";
using (SqlCommand command = new SqlCommand(procedure, connection))
{
command.CommandType = CommandType.StoredProcedure;
command.CommandTimeout = 300;
command.Parameters.Add(
new SqlParameter("#JobID", id));
SqlParameter ErrorString = new SqlParameter("#ErrorString", ReturnMessage);
ErrorString.Direction = ParameterDirection.Output;
ErrorString.Size = 4000;
command.Parameters.Add(ErrorString);
connection.Open();
command.ExecuteNonQuery();
// Save Outout Param
ReturnMessage = ErrorString.Value.ToString();
}
}
return Content("You requested the to create bundles and cartons for job ID " + id.ToString() + "<br />Result: " + ReturnMessage + "<br /> ");
}
I want to display the results to the user and them give them ability to return to the jobs view.
I tried this as my return value:
return Content("You requested the to create bundles and cartons for job ID " + id.ToString() + "Result: " + ReturnMessage + " Return to Jobs");
This displays the results and the link:
But the link points to http://localhost:59971/Jobs/CreateBandC/~/Jobs/ instead of http://localhost:59971/Jobs/
How can I fix that?
Is there a better way to return the results?
I'm under some time pressure, so this approach would do for now, but I'd like to actually figure out how to return a more complex type and nicer view
Thanks
mark
Looks like this requires database changes to fix the link. This is typically a result of poor design and tight coupling. So, go in the database and change the a tag in your stored procedure to get the desired result.

YouTube : This video contains content from vevo?

I am trying to play a YouTube video in my application. Everything works fine. However, when I try to watch a video that contains content from Vevo, it fails.
I had also tried to pass el=vevo in get_video_info:
http://www.youtube.com/get_video_info?video_id=uuZE_IRwLNI&el=vevo&ps=default&eurl=&gl=US&hl=en
stream
{
"fallback_host" = "tc.v12.cache7.googlevideo.com";
itag = 22;
quality = hd720;
s = "8E6E5D13EB65FB653B173B94CB0BCC3A20853F5EDE8.5E2E87DF33EEDE165FEA90109D3C7D5DADA06B6BB60";
type = "video/mp4; codecs=\"avc1.64001F, mp4a.40.2\"";
url = "http://r7---sn-cvh7zn7r.googlevideo.com/videoplayback?pcm2fr=yes&sver=3&expire=1393773646&itag=22&id=bae644fc84702cd2&upn=SjZd81MudQs&sparams=gcr%2Cid%2Cip%2Cipbits%2Citag%2Cpcm2fr%2Cratebypass%2Csource%2Cupn%2Cexpire&ms=au&gcr=in&mt=1393747698&source=youtube&ratebypass=yes&ipbits=0&fexp=935620%2C919120%2C912523%2C932288%2C914084%2C916626%2C937417%2C937416%2C913434%2C932289%2C936910%2C936913%2C902907&mv=m&key=yt5&ip=103.250.162.79";
}
When I use url its not playing. Is there any solution?
get_video_info works only for the videos which are allowed to be viewed as embedded videos in other websites. I struggled a lot with get_video_info but could find any solution for vevo. however I was able to make it work by retrieving the actual video page, in actual video page you have to grab player version and hit url (specified in code) to grab the streams links and actual signatures.
youtube might change this in future but today following solutions is working great for me.
Its c# you should know how to convert it into object-C, entry point of following code is ExtractUrls function and remember to pass it html of video page.
e.g. html content of http://www.youtube.com/watch?v=J5iS3tULXMQ&nomobile=1
private static List<string> ExtractUrls(string html)
{
string Player_Version = Regex.Match(html, #"""\\/\\/s.ytimg.com\\/yts\\/jsbin\\/html5player-(.+?)\.js""").Groups[1].ToString();
string Player_Code = new WebClient().DownloadString("http://s.ytimg.com/yts/jsbin/" + "html5player-" + Player_Version + ".js");
html = Uri.UnescapeDataString( Regex.Match(html, #"""url_encoded_fmt_stream_map"":\s+""(.+?)""", RegexOptions.Singleline).Groups[1].ToString());
var Streams = Regex.Matches(html, #"(^url=|(\\u0026url=|,url=))(.+?)(\\u0026|,|$)");
var Signatures = Regex.Matches(html, #"(^s=|(\\u0026s=|,s=))(.+?)(\\u0026|,|$)");
List<string> urls = new List<string>();
for (int i = 0; i < Streams.Count - 1; i++)
{
string URL = Streams[i].Groups[3].ToString();
if (Signatures.Count > 0)
{
string Sign = Sign_Decipher(Signatures[i].Groups[3].ToString(), Player_Code);
URL += "&signature=" + Sign;
}
urls.Add(URL.Trim());
}
return urls;
}
public static string Sign_Decipher(string s, string Code)
{
string Function_Name = Regex.Match(Code, #"signature=(\w+)\(\w+\)").Groups[1].ToString();
var Function_Match = Regex.Match(Code, "function " + Function_Name + #"\((\w+)\)\{(.+?)\}",RegexOptions.Singleline);
string Var = Function_Match.Groups[1].ToString();
string Decipher = Function_Match.Groups[2].ToString();
var Lines = Decipher.Split(';');
for (int i = 0; i < Lines.Length; i++)
{
string Line = Lines[i].Trim();
if (Regex.IsMatch(Line, Var + "=" + Var + #"\.reverse\(\)"))
{
char[] charArray = s.ToCharArray();
Array.Reverse(charArray);
s = new string(charArray);
}
else if (Regex.IsMatch(Line, Var + "=" + Var + #"\.slice\(\d+\)"))
{
s = Slice(s, Convert.ToInt32(Regex.Match(Line, Var + "=" + Var + #"\.slice\((\d+)\)").Groups[1].ToString()));
}
else if (Regex.IsMatch(Line, Var + #"=\w+\(" + Var + #",\d+\)"))
{
s = Swap(s, Convert.ToInt32(Regex.Match(Line, Var + #"=\w+\(" + Var + #",(\d+)\)").Groups[1].ToString()));
}
else if (Regex.IsMatch(Line, Var + #"\[0\]=" + Var + #"\[\d+%" + Var + #"\.length\]"))
{
s = Swap(s, Convert.ToInt32(Regex.Match(Line, Var + #"\[0\]=" + Var + #"\[(\d+)%" + Var + #"\.length\]").Groups[1].ToString()));
}
}
return s;
}
private static string Slice(string Input, int Length)
{
return Input.Substring(Length, Input.Length - 1);
}
private static string Swap(string Input, int Position)
{
var Str = new StringBuilder(Input);
var SwapChar = Str[Position];
Str[Position] = Str[0];
Str[0] = SwapChar;
return Str.ToString();
}
credit goes to comments under this code project artical
Certain videos have a domain-level whitelist or blacklist applied to them. This is done at the discretion of the content owner.
If there is a whitelist or a blacklist, and the domain of the embedding site can't be determined (perhaps because of there not being a real referring domain in the case of your native application), then the default behavior is to block playback.
This blog post has a bit more detail as well: http://apiblog.youtube.com/2011/12/understanding-playback-restrictions.html
That specific video can only be played when it's embedded on a real website with a real referring URL, due to the way domain white/blacklisting works. And, we don't expose those lists via the API. It's a longstanding feature request
YouTube video URL should contain a signature (which is included in the 's' field), to use this url, you need to decrypt the signature first and add it to the URL.
The signature decryptor can be found on the web page of the video (i.e. youtube.com/watch?v=VIDEO_ID).
I can't provide more info as it would be against YouTube terms of service :).

Resources